package flc.ast.adapter;

import android.graphics.Color;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;

public class MusicTitleAdapter extends StkProviderMultiAdapter<String> {

    private int selPos = 0;

    public MusicTitleAdapter() {
        super(1);
        addItemProvider(new MusicTitleItemProvider());
    }

    public void setSelPos(int selPos) {
        if (this.selPos != selPos) {
            this.selPos = selPos;
            notifyDataSetChanged();
        }
    }

    private class MusicTitleItemProvider extends BaseItemProvider<String> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_music_title;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, String s) {
            TextView tvMusicTitleName = baseViewHolder.getView(R.id.tvMusicTitleName);
            tvMusicTitleName.setText(s);

            int position = baseViewHolder.getBindingAdapterPosition();
            if (position == selPos) {
                baseViewHolder.setImageResource(R.id.ivMusicTitleIcon, R.drawable.xz1);
                tvMusicTitleName.setTextColor(Color.parseColor("#292929"));
            } else {
                baseViewHolder.setImageResource(R.id.ivMusicTitleIcon, R.drawable.shape_music_title);
                tvMusicTitleName.setTextColor(Color.parseColor("#80FFFFFF"));
            }
        }
    }
}
